package com.example.oasystem.controller.list;


import com.example.oasystem.dao.login.AoaUserDao;
import com.example.oasystem.entity.list.AoaSysMenu;

import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.service.AoaSysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AoaSysMenuController {
    @Autowired
    AoaUserDao aoaUserDao;
    @Autowired
    AoaSysMenuService aoaSysMenuService;

    @RequestMapping("/index")
    public  String toIndex(HttpServletRequest request, Model model){
        //AoaUser aoaUser = aoaUserDao.selectById(1);
        System.out.println("123123123");
        AoaUser user = (AoaUser)request.getSession().getAttribute("user");
        System.out.println(user);
        Long roleId = user.getRoleId();
        List<AoaSysMenu> aoaSysMenus1 = aoaSysMenuService.selectOneMenuAll(roleId);
        List<AoaSysMenu> aoaSysMenus2 = aoaSysMenuService.selectTwoMenuAll(roleId);

        model.addAttribute("oneMenuAll",aoaSysMenus1);
        model.addAttribute("twoMenuAll",aoaSysMenus2);
        return "index/index";
    }

    @RequestMapping("/loginout")
    public String loginout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "login/login";
    }
}
